package com.gensdai.leliang.remoteInterface;

import android.content.Context;

import com.gensdai.leliang.entity.HomeBean;
import com.gensdai.leliang.entity.parseBean.BaseParse;
import com.gensdai.leliang.entity.parseBean.BaseParseList;
import com.gensdai.leliang.entity.parseBean.ParentBean;
import com.gensdai.leliang.entity.parseBean.ProductInfo;
import com.gensdai.leliang.entity.parseBean.RegisterParse;
import com.gensdai.leliang.retrofitUtils.conver.StringConver;
import com.gensdai.leliang.retrofitUtils.okhttputils.Okhttp3Utils;
import com.github.aurae.retrofit2.LoganSquareConverterFactory;

import java.util.Map;

import io.reactivex.Observable;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * 具体调用interface
 * Created by liutao on 2017/5/23.
 */

public class ApiService {
    InterfaceCodeUtils api;

    public static ApiService service;

    private ApiService(InterfaceCodeUtils api) {
        this.api = api;
    }

    //单例
    public static ApiService getInstance() {

        if (service == null) {
            //注：addConverterFactory是有先后顺序的，如果有多个ConverterFactory都支持同一种类型，那么就是只有第一个才会被使用
            Retrofit retrofit = new Retrofit.Builder().baseUrl(URLConfig.BASEURL)
                    .addConverterFactory(StringConver.StringConverterFactory.create()) //可以添加多种解析方式 可以直接取字符 如果有多种同样的解析方式，默认使用第一种
                    .addConverterFactory(LoganSquareConverterFactory.create())  //返回json处理用logansquare处理
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())  //返回格式统一用Observable
                    .build();
            service = new ApiService(retrofit.create(InterfaceCodeUtils.class));
        }
        return service;


    }

    //每次请求都带Cookie
    public static ApiService getInstance(Context context) {

        if (service == null) {
            OkHttpClient okHttpC = Okhttp3Utils.getOkhttpClient(context);
            //注：addConverterFactory是有先后顺序的，如果有多个ConverterFactory都支持同一种类型，那么就是只有第一个才会被使用
            Retrofit retrofit = new Retrofit.Builder().baseUrl(URLConfig.BASEURL)
                    .client(okHttpC)
                    .addConverterFactory(StringConver.StringConverterFactory.create()) //可以添加多种解析方式 可以直接取字符 如果有多种同样的解析方式，默认使用第一种
                    .addConverterFactory(LoganSquareConverterFactory.create())  //返回json处理用logansquare处理
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())  //返回格式统一用Observable
                    .build();
            service = new ApiService(retrofit.create(InterfaceCodeUtils.class));
        }
        return service;


    }


    /**
     * 该类所有方法直接请求interface定义的接口,所有返回值统一使用rxjava的observable返回
     */


    public Observable<RegisterParse> RegisterRequest(Map<String, String> params) {
        return api.RegisterRequest(params);
    }

    public Observable<String> Register2Str(Map<String, String> params) {
        return api.RegisterRequest2Str(params);
    }

    public Observable<String> LoginRequest2Str(Map<String, String> params) {
        return api.LoginRequest2Str(params);
    }

    public Observable<String> QueryAccountRequest2Str(Map<String, String> params) {
        return api.QueryAccountRequest2Str(params);
    }

    public Observable<String> PayRequestStr(Map<String, String> params) {
        return api.PayRequestStr(params);
    }

    public Observable<BaseParse<ProductInfo>> getProductDetail(Map<String, String> params) {
        return api.getProductDetail(params);
    }

    public Observable<ParentBean> addShopCar(Map<String, String> params) {
        return api.addShopCar(params);
    }

    public Observable<String> AddressRequestStr(Map<String, String> params) {
        return api.AddressRequestStr(params);
    }

    public Observable<String> INVITE_FRIEND_RECORD(Map<String, String> params) {
        return api.INVITE_FRIEND_RECORD(params);
    }

    public Observable<String> PERSONAL_CHANGE_PHONE(Map<String, String> params) {
        return api.PERSONAL_CHANGE_PHONE(params);
    }

    public Observable<String> SETMMRequestStr(Map<String, String> params) {
        return api.SETMMRequestStr(params);
    }

    public Observable<String> INVITE_FRIEND_CODE(Map<String, String> params) {
        return api.INVITE_FRIEND_CODE(params);
    }

    public Observable<String> ConfirmReceipt(Map<String, String> params) {
        return api.ConfirmReceipt(params);
    }

    public Observable<String> RemoveAddressRequestStr(Map<String, String> params) {
        return api.RemoveAddressRequestStr(params);
    }

    public Observable<String> UpdateRequestStr(Map<String, String> params) {
        return api.UpdateRequestStr(params);
    }

    public Observable<String> AddressRequestStr(String name,
                                                String userId,
                                                String provinceId,
                                                String cityId,
                                                String districtId,
                                                String detailedAddress,
                                                String phone) {
        return api.AddressRequestStr(name,
                userId,
                provinceId,
                cityId,
                districtId,
                detailedAddress,
                phone);
    }

    public Observable<String> EditAddressRequestStr(Map<String, String> params) {
        return api.EditAddressRequestStr(params);
    }

    public Observable<String> QUERY_THIRDPARTY_STATE(Map<String, String> params) {
        return api.QUERY_THIRDPARTY_STATE(params);
    }

    public Observable<String> SET_PERSONAL_GESTATION(Map<String, String> params) {
        return api.SET_PERSONAL_GESTATION(params);
    }

    public Observable<String> QUERY_PERSONAL_GESTATION(Map<String, String> params) {
        return api.QUERY_PERSONAL_GESTATION(params);
    }

    public Observable<String> REMOVE_THIRDPARTY_BIND(Map<String, String> params) {
        return api.REMOVE_THIRDPARTY_BIND(params);
    }

    public Observable<String> BIND_THIRDPARTY_DIRECTILY(Map<String, String> params) {
        return api.BIND_THIRDPARTY_DIRECTILY(params);
    }

    public Observable<String> OrderManageRequestStr(Map<String, String> params) {
        return api.OrderManageRequestStr(params);
    }

    public Observable<String> SetDefaultAddressRequestStr(Map<String, String> params) {
        return api.SetDefaultAddressRequestStr(params);
    }

    public Call<ResponseBody> MAKE_VERIFY_CODE(Map<String, String> params) {
        return api.MAKE_VERIFY_CODE(params);
    }

    public Observable<String> CQUERY_MESSAGE_COUNT_Receipt(Map<String, String> params) {
        return api.CQUERY_MESSAGE_COUNT_Receipt(params);
    }

    public Observable<String> SelectShopCarRequestStr(Map<String, String> params) {
        return api.SelectShopCarRequestStr(params);
    }

    public Observable<String> PayGrowth(Map<String, String> params) {
        return api.PayGrowth(params);
    }

    public Observable<String> INVALID_MES_STATUS_Receipt(Map<String, String> params) {
        return api.INVALID_MES_STATUS_Receipt(params);
    }

    public Observable<String> Check_UnputCode(Map<String, String> params) {
        return api.Check_UnputCode(params);
    }

    public Observable<String> sendChecCode(Map<String, String> params) {
        return api.sendChecCode(params);
    }

    public Observable<String> Query_Message_Receipt(Map<String, String> params) {
        return api.Query_Message_Receipt(params);
    }

    public Observable<String> Set_Phone_Message_Receipt(Map<String, String> params) {
        return api.Set_Phone_Message_Receipt(params);
    }

    public Observable<String> PERSONAL_CHANGE_INFO_Receipt(Map<String, String> params) {
        return api.PERSONAL_CHANGE_INFO_Receipt(params);
    }

    public Observable<String> PERSONAL_BIND_EMAIL_Receipt(Map<String, String> params) {
        return api.PERSONAL_BIND_EMAIL_Receipt(params);
    }

    public Observable<String> GET_PERSONAL_INFO_Receipt(Map<String, String> params) {
        return api.GET_PERSONAL_INFO_Receipt(params);
    }

    public Observable<String> PERSONAL_CHECK_EMAIL_Receipt(Map<String, String> params) {
        return api.PERSONAL_CHECK_EMAIL_Receipt(params);
    }

    public Observable<String> PERSONAL_CHANGE_INFO_IMG_Receipt(Map<String, RequestBody> params) {
        return api.PERSONAL_CHANGE_INFO_IMG_Receipt(params);
    }

    public Observable<String> CHANGE_MSG_STATUS_Receipt(Map<String, String> params) {
        return api.CHANGE_MSG_STATUS_Receipt(params);
    }

    public Observable<String> forgetLoginPassword(Map<String, String> params) {
        return api.forgetLoginPassword(params);
    }

    public Observable<String> DeleteShopCarRequestStr(Map<String, String> params) {
        return api.DeleteShopCarRequestStr(params);
    }

    public Observable<String> UpdateShopCarRequestStr(Map<String, String> params) {
        return api.UpdateShopCarRequestStr(params);
    }

    public Observable<String> FindGold(Map<String, String> params) {
        return api.FindGold(params);
    }

    public Observable<String> FindGrow(Map<String, String> params) {
        return api.FindGrow(params);
    }
    public Observable<String> FindGrowShell(Map<String, String> params) {
        return api.FindGrowShell(params);
    }

    public Observable<String> QueryRequestStr(Map<String, String> params) {
        return api.QueryRequestStr(params);
    }

    public Observable<String> PAY_PASSWORDRequestStr(Map<String, String> params) {
        return api.PAY_PASSWORDRequestStr(params);
    }
    public Observable<String> AddZFBRequestStr(Map<String, String> params) {
        return api.AddZFBRequestStr(params);
    }

    public Observable<String> CHANGE_PAY_PASSWORD(Map<String, String> params) {
        return api.CHANGE_PAY_PASSWORD(params);
    }

    public Observable<ParentBean> setupPayPass(Map<String, String> params) {
        return api.setupPayPass(params);
    }

    public Observable<ParentBean> payBalance(Map<String, String> params) {
        return api.payBalance(params);
    }

    public Observable<BaseParse<BaseParse.properOrder>> postOrder(Map<String, String> params) {
        return api.postOrder(params);
    }

    public Observable<String> tixian(Map<String, String> params) {
        return api.tixian(params);
    }

    /*获取订单详情*/
    public Observable<BaseParse<BaseParse.OrderInfo>> getOrderInfo(Map<String, String> params) {
        return api.getOrderInfo(params);
    }

    public Observable<BaseParse<HomeBean>> getHome() {
        return api.getHome();
    }
    public Observable<BaseParseList<ProductInfo>> getFenleiList(Map<String, String> params) {
        return api.getFenleiList(params);
    }
    public Observable<BaseParse<String>> postOrderCancel(Map<String, String> params) {
        return api.postOrderCancel(params);
    }

}
